package main

import (
	"fmt"
)

type Duck interface {
	Swim(i interface{})    // 游泳
	Feathers() // 羽毛
}

type QuackDuck interface {
	Quack()  // 嘎嘎叫
	Duck     // 嵌入接口
}

// RealDuck - 真正的鸭子
type RealDuck struct { }

func (RealDuck) Swim(i interface{}) {
	fmt.Printf("用鸭璞向后划水 %v \n",i)
}

func (RealDuck) Feathers() {
	fmt.Println("遇到水也不会湿的羽毛")
}

func (RealDuck) Quack() {
	fmt.Println("嘎~ 嘎~ 嘎~")
}

// ToyDuck - 玩具鸭
type ToyDuck struct { }

func (ToyDuck) Swim(i interface{}) {
	fmt.Printf("以固定的速度向前移动 %v \n",i)
}

func (ToyDuck) Feathers() {
	fmt.Println("白色的固定的塑料羽毛")
}

//func main1(){
//	var duck Duck
//	duck = ToyDuck{}
//	duck.Swim()
//	duck.Feathers()
//}

func Factory(name string) Duck {
	switch name {
	case "toy":
		return &ToyDuck{}
	case "real":
		return &RealDuck{}
	default:
		panic("No such duck")
	}
}

func main() {
	duck := Factory("real")
	duck.Swim(123)
	duck.Feathers()

	toyDuck := Factory("toy")
	toyDuck.Swim("ok")
	toyDuck.Feathers()
}